#include "stdafx.h"
#include <boost/test/auto_unit_test.hpp>
#include "detail/bmock_raw_len.hpp"
#include "bmock_util.hpp"
#include <boost/scoped_array.hpp>
#include "detail/bmock_test_control_tools.hpp"

namespace bmock {
	static const unsigned char expected[] = {0x32,0x00,0x00,0x00
		,0x3C,0x00,0x00,0x00
		,0x14,0x00,0x00,0x00
		,0x1A,0x00,0x00,0x00
		,0xAB,0xAB,0xAB,0xAB};

	static const size_t L0 = sizeof(expected);
	static const size_t L1 = 5;
	static const size_t L2 = 10;
	static const size_t L3 = 12;
	static const size_t L4 = 20;

	BOOST_AUTO_TEST_CASE(test_raw_len_put) {
		const raw_len  rl(L1,L2,L3);
		boost::scoped_array<unsigned char> buf(new unsigned char[L0]);
		const void    *result;


		BOOST_CHECK_NO_THROW(result = rl.put(buf.get()));
		BOOST_CHECK_EQUAL(mismatch_at(buf.get(),buf.get()+L0,expected),L0);
		BOOST_CHECK_EQUAL(result,buf.get()+L4);
	}

	BOOST_AUTO_TEST_CASE(test_raw_len_get_OK) {
		raw_len                  rl;
		const void              *result = NULL;
		const char               name[] = "raw_mem(out_buf,L1)";
		const control_tools_ptr  t(new test_control_tools());
		raw_len_checker          chk(t);

		chk.set_location(location(__FILE__,__LINE__+1));
		BOOST_CHECK_NO_THROW(result = rl.get(expected,name,chk));
		BOOST_CHECK_EQUAL(rl.get_o_length(),L1*L3);
		BOOST_CHECK_EQUAL(result,expected+L4);
	}
}